﻿#include<stdio.h>
#include<stdlib.h>
struct ListNode
{
	int val;
	struct ListNode* next;
};
int kthToLast(struct ListNode* head, int k)
{
	int n = 0;
	struct ListNode* cur = head;
	while (cur)
	{
		cur = cur->next;
		n++;
	}
	cur = head;
	int k1 = n - k;
	while (k1--)
	{
		cur = cur->next;
	}
	return cur->val;
}
 int main()
 {
	 int k = 2;
	 struct ListNode* head = (struct ListNode*)malloc(sizeof(struct ListNode));
	 head->val = 1;
	 struct ListNode* node1 = (struct ListNode*)malloc(sizeof(struct ListNode));
	 node1->val = 2;
	 struct ListNode* node2 = (struct ListNode*)malloc(sizeof(struct ListNode));
	 node2->val = 3;
	 struct ListNode* node3 = (struct ListNode*)malloc(sizeof(struct ListNode));
	 node3->val = 4;
	 struct ListNode* node4 = (struct ListNode*)malloc(sizeof(struct ListNode));
	 node4->val = 5;
	 head->next = node1;
	 node1->next = node2;
	 node2->next = node3;
	 node3->next = node4;
	 node4->next = NULL;
	 int ret = kthToLast(head,k);
	 printf("%d", ret);
	 return 0;
 }
